package dedup

import (
	"context"
	"fmt"

	"github.com/smart-snapshotter/pkg/types"
)

// MockDedupEngine is a mock implementation of DedupEngine for testing
type MockDedupEngine struct {
	stats types.DedupStats
}

// NewMockEngine creates a new mock deduplication engine
func NewMockEngine() *MockDedupEngine {
	return &MockDedupEngine{
		stats: types.DedupStats{
			TotalFiles:   0,
			UniqueFiles:  0,
			TotalBlocks:  0,
			UniqueBlocks: 0,
			SpaceSaved:   0,
			DedupRatio:   0.0,
		},
	}
}

// AddFile adds a file to the deduplication engine (mock implementation)
func (m *MockDedupEngine) AddFile(ctx context.Context, path string, data []byte) error {
	m.stats.TotalFiles++
	// Simulate some deduplication
	if m.stats.TotalFiles%3 == 0 {
		m.stats.UniqueFiles++
		m.stats.SpaceSaved += int64(len(data))
	}
	if m.stats.TotalFiles > 0 {
		m.stats.DedupRatio = float64(m.stats.SpaceSaved) / float64(m.stats.TotalFiles*1024) // Assume average file size 1KB
	}
	return nil
}

// GetFile retrieves a file from the deduplication engine (mock implementation)
func (m *MockDedupEngine) GetFile(ctx context.Context, hash string) ([]byte, error) {
	// Return mock data
	return []byte("mock file content"), nil
}

// GetStats returns deduplication statistics (mock implementation)
func (m *MockDedupEngine) GetStats(ctx context.Context) (types.DedupStats, error) {
	return m.stats, nil
}

// ProcessSnapshot processes a snapshot for deduplication (mock implementation)
func (m *MockDedupEngine) ProcessSnapshot(ctx context.Context, snapshotID string, path string) error {
	// Mock implementation - just log the operation
	fmt.Printf("Mock processing snapshot %s at path %s\n", snapshotID, path)
	return nil
}

// RemoveSnapshot removes snapshot deduplication data (mock implementation)
func (m *MockDedupEngine) RemoveSnapshot(ctx context.Context, snapshotID string) error {
	// Mock implementation - just log the operation
	fmt.Printf("Mock removing snapshot %s dedup data\n", snapshotID)
	return nil
}

// GetSnapshotUsage returns snapshot usage information (mock implementation)
func (m *MockDedupEngine) GetSnapshotUsage(ctx context.Context, snapshotID string) (types.Usage, error) {
	return types.Usage{
		Size:   1024 * 1024, // 1MB mock size
		Inodes: 100,
	}, nil
}